import 'package:boss/models/store_area.dart';
import 'package:boss/models/store_table.dart';
import 'package:boss/provider/table_provider.dart';
import 'package:boss/ui/widget/sortList/sort_item_data.dart';
import 'package:flutter/material.dart';
import 'package:hi_common/hi_common.dart';
import 'package:provider/provider.dart';

class SortTableProvider extends ChangeNotifier {
  StoreArea selectedArea;

  List<SortItemData<StoreTable>> tables = [];

  setArea(StoreArea area) {
    selectedArea = area;
    tables = area.storeTableList.map((item) => SortItemData(title: item.tableName, value: item)).toList();
    notifyListeners();
  }

  SortTableProvider() {
    var tableProvider = Provider.of<TableProvider>(
      GlobalPageContext.instance.context,
      listen: false,
    );

    if (tableProvider.storeAreas.length > 0) {
      setArea(tableProvider.storeAreas[0]);
    }
  }
}
